package com.goldcn.user.service;

import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by Administrator on 2016/7/13.
 */
@Service
@Transactional
public class CodeService {
    @Autowired
    RedisService redisService;

    public String verificationCode(String id,String code){
        Object o=redisService.loadKey(id);
        if(o!=null){
            if(id.equals(o.toString())){
                Object cd=redisService.loadKey(code.toLowerCase());
                if(cd!=null){
                    if(code.equalsIgnoreCase(cd.toString())){
                        return  "1";
                    }
                }
            }
        }
        return  "0";
    }

    public String verificationCode1(JSONObject json){
        JSONObject jso= JSONObject.fromObject(json);
        String id=jso.optString("id","");
        String code=jso.optString("code","");
        Object o=redisService.loadKey(id);
        if(o!=null){
            if(id.equals(o.toString())){
                Object cd=redisService.loadKey(code);
                if(cd!=null){
                    if(code.equalsIgnoreCase(cd.toString())){
                        return  "1";
                    }
                }
            }
        }
        return  "0";
    }
}
